﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using CorreoSocialWeb.Models;
using CorreoSocialWeb.Views;

using Subgurim.Controles;
using Subgurim.Controles.GoogleChartIconMaker;

namespace CorreoSocialWeb.Views
{
    public class CargadorDeMarkers
    {
        public static void Cargar(CoordenadasDeSesionHelper coordenadas, GMap mapa)
        {
            PinLetter pinLetterOrigen = new PinLetter("O", System.Drawing.Color.Yellow, System.Drawing.Color.Black);
            PinLetter pinLetterDestino = new PinLetter("D", System.Drawing.Color.LightGreen, System.Drawing.Color.Black);

            GMarker marker = new GMarker(coordenadas.Origen, new GMarkerOptions(new GIcon(pinLetterOrigen.ToString(), pinLetterOrigen.Shadow())));
            marker.options.title = "Origen";
            
            if (!coordenadas.SinOrigen)
                mapa.Add(marker);

            marker = new GMarker(coordenadas.Destino, new GMarkerOptions(new GIcon(pinLetterDestino.ToString(), pinLetterOrigen.Shadow())));
            marker.options.title = "Destino";

            if (!coordenadas.SinDestino)
                mapa.Add(marker);

            GLatLngBounds bounds = new GLatLngBounds(
                     coordenadas.SinOrigen ? CoordenadasInicioBuenosAires.Get() : coordenadas.Origen
                    , coordenadas.SinDestino ? CoordenadasInicioBuenosAires.Get() : coordenadas.Destino
                    );

            if (!coordenadas.SinDatos)
            {
                mapa.GZoom = mapa.getBoundsZoomLevel(bounds);
                mapa.setCenter(bounds.getCenter());
            }
            else
            {
                mapa.setCenter(CoordenadasInicioBuenosAires.Get());
                mapa.GZoom = 11;
            }
        }

        public static string MapaClick(GMap mapa, CoordenadasDeSesionHelper coordenadasDeSesion, GAjaxServerEventArgs e)
        {
            if (coordenadasDeSesion.SinOrigen)
            {
                GMarker marker;

                PinLetter pinLetterOrigen = new PinLetter("O", System.Drawing.Color.Yellow, System.Drawing.Color.Black);

                marker = new GMarker(e.point, new GMarkerOptions(new GIcon(pinLetterOrigen.ToString(), pinLetterOrigen.Shadow())));
                marker.options.title = "Origen";
                mapa.Add(marker);

                coordenadasDeSesion.Origen = e.point;

                return marker.ToString(e.map);
            }
            else if (coordenadasDeSesion.SinDestino)
            {
                GMarker marker;

                PinLetter pinLetterDestino = new PinLetter("D", System.Drawing.Color.LightGreen, System.Drawing.Color.Black);

                marker = new GMarker(e.point, new GMarkerOptions(new GIcon(pinLetterDestino.ToString(), pinLetterDestino.Shadow())));
                marker.options.title = "Destino";
                mapa.Add(marker);

                coordenadasDeSesion.Destino = e.point;

                return marker.ToString(e.map);
            }

            return string.Empty;
        }
    }
}